<template>
	<view class="page">
		<!-- 头部搜索 -->
		<view class="header">
			<view class="searchBox">
				<u-icon name="search" style="font-size: 36rpx; color: #A8B5C5;"></u-icon>
				<u-input v-model="keywords" height="72" style="width: 540rpx; margin-left: 16rpx;"
					placeholder="请输入搜索内容" />
				<view class="search" @click="search()">
					搜索
				</view>
			</view>
		</view>
		<view class="tip">* 如申请签约协助功能，需将您佣金的30%给到协助人员 *</view>
		<!-- 公司列表项/跟进的状态 -->
		<view class="item" v-for="(item,index) in list" :key="index">
			<view class="titleBox">
				<view class="txt">
					{{item.companyName}}
				</view>
				<!-- 给标签动态添加颜色 颜色已写好在样式在后面写的，自己调一下 -->
				<!-- <view class="tag" :class="[ type == false ? 'zhengZai':'fishu']" @click="modelShow">
					签约协助
				</view> -->
				<view class="tag" v-if="item.groundPushHelp == null" @click="modelShow(item.id)">
					签约协助
				</view>
				
				<view class="tag" v-if="item.groundPushHelp.status == 0">
					待分配
				</view>
				
				<view class="tag" v-if="item.groundPushHelp.status == 1">
					跟进中
				</view>
			</view>
			<!-- 编号 -->
			<view class="biaoHao" v-if="item.houseNum">
				{{item.houseNum}}
			</view>
			<view class="list">
				<view class="left">
					电话：
				</view>
				<view class="right">
					<view class="centent">
						{{item.companyMobile}}
					</view>
				</view>
			</view>
			<view class="list">
				<!-- 信息标题 -->
				<view class="left">
					预估电量：
				</view>
				<view class="right">
					<view class="centent">
						{{item.electricityNum}}Kwh
					</view>
					<view class="xiangQing"
						@click="$next(`/pages/functionCore/customer/detail?id=${item.id}`)">
						详情 >
					</view>
				</view>
			</view>
			<view class="list">
				<!-- 信息标题 -->
				<view class="left">
					负责人：
				</view>
				<view class="right">
					<view class="centent">
						{{item.companyPerson}}
					</view>
				</view>
			</view>
			<view class="list">
				<!-- 信息标题 -->
				<view class="left">
					协助人名称：
				</view>
				<view class="right">
					<view class="centent">
						{{item.groundPushHelp.help.realname || "待分配"}}
					</view>
				</view>
			</view>

			<view class="list">
				<!-- 信息标题 -->
				<view class="left">
					协助人电话：
				</view>
				<view class="right">
					<view class="centent">
						{{item.groundPushHelp.help.mobile || "待分配"}}
					</view>
				</view>
			</view>

		</view>
		<!-- 加载更多 -->
		<u-loadmore v-if="list.length !== 0" :status="status" :load-text="loadText" />
		<image v-else src="@/static/image/empty.png" mode="widthFix" class="is-empty"></image>
		<!-- 新建按钮 -->
		<view class="add" @click="$next(`/pages/functionCore/groundPush/intendedCustomer`)">
			+
		</view>
		<u-modal v-model="show" @confirm="confirm" ref="uModal" :async-close="true" show-cancel-button=true></u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				keywords: '',
				page: 1,
				limit: 10,
				more: false,
				// 页面数据初始化状态
				loadText: {
					loadmore: '轻轻上拉，加载更多',
					loading: '努力加载中',
					nomore: '我也是有底线的'
				},
				list: [],

			}
		},
		mounted() {
			uni.$on('reloadData', (res) => {
				this.page = 1
				this.getCustomRes()
			})
		},
		onLoad() {
			this.getCustomRes()
		},
		//下拉刷新
		onPullDownRefresh() {
			this.page = 1
			this.getCourseRes()
		},
		//上拉加载
		onReachBottom() {
			if (this.page == 1) {
				return
			}
			if (this.more) {
				this.getCourseRes()
			}
		},
		methods: {

			search() {
				this.page = 1
				this.getCustomRes()
			},
			getCustomRes() {
				this.$axios.request(this.$api.getCustomRes, "GET", {
					limit: this.limit,
					page: this.page,
					type: 1,
					keywords: this.keywords,
					orderField: 'id',
					order: 'desc'
				}).then((val) => {
					uni.stopPullDownRefresh();
					this.list = this.page == 1 ? val.data.list : this.list.concat(val.data.list)
					if (Math.ceil(val.data.total / this.limit) > this.page) {
						this.more = true;
						this.page++
					} else {
						this.more = false;
					}
				})
			},
			modelShow(id) {
				this.$axios.request(this.$api.addGroundHelpPush,"POST",{
					customId:id
				}).then((val) => {
					uni.showModal({
						title:"提示",
						content:"提交成功，等待后台人员分配地推协助",
						showCancel:false,
						success: () => {
							this.page = 1
							this.getCustomRes()
						}
					})
				})
				
			}
		}
	}
</script>

<style>
	.page {
		width: 100%;
		height: 100vh;
		overflow-y: auto;
		background-color: #f9f9f9;
	}
	.tip{
		font-size: 12px;
		    color: #F44336;
		    text-align: center;
	}
	.header {
		display: flex;
		justify-content: center;
		align-items: center;
		width: 100%;
		height: 104rpx;
		background-color: #FFFFFF;

	}

	.searchBox {
		display: flex;
		justify-content: center;
		align-items: center;
		width: 702rpx;
		height: 72rpx;
		background-color: #f0f0f0;
	}

	.search {
		width: 90rpx;
		height: 40rpx;
		font-size: 32rpx;
		font-family: "PingFang SC";
		font-weight: 300;
		line-height: 40rpx;
		color: #3975EA;
		border-left: 2rpx solid #A8B5C5;
		text-align: center;
		opacity: 1;
	}

	.item {
		overflow: hidden;
		width: 100%;
		background-color: #fff;
		margin: 16rpx 0rpx;
		padding:16rpx 0rpx;
	}

	.titleBox {
		display: flex;
		justify-content: space-between;
		align-items: center;
		height: 42rpx;
		margin: 0 32rpx;
	}

	.txt {
		height: 40rpx;
		font-size: 32rpx;
		font-family: "PingFang SC";
		font-weight: 600;
		line-height: 40rpx;
		color: #333333;
	}

	.tag {
		height: 40rpx;
		font-size: 24rpx;
		font-family: "PingFang SC";
		font-weight: 400;
		line-height: 40rpx;
		color: #F5F5F5;
		padding: 0 15rpx;
		background-color: #3975EA;
	}

	.biaoHao {
		height: 28rpx;
		font-size: 24rpx;
		font-family: "PingFang SC";
		font-weight: 400;
		line-height: 20rpx;
		color: #BBBBBB;
		margin: 15rpx 0 18rpx;
		margin-left: 32rpx;
	}

	.list {
		display: flex;
		border-bottom: 2px solid #f9f9f9;
		justify-content: space-between;
		align-items: center;
		width: 100%;
		height: 65rpx;
	}
	.list:last-child{
		border-bottom: none;
	}

	.left {
		width: 188rpx;
		height: 33rpx;
		font-size: 28rpx;
		font-family: "PingFang SC";
		font-weight: 600;
		line-height: 33rpx;
		color: #333333;
		margin-left: 32rpx;
	}

	.right {
		display: flex;
		justify-content: space-between;
		align-items: center;
		width: 590rpx;
		height: 33rpx;
	}

	.centent {
		font-size: 28rpx;
		font-family: "PingFang SC";
		font-weight: 300;
		color: #BBBBBB;
	}

	.xiangQing {
		height: 33rpx;
		font-size: 28rpx;
		font-family: "PingFang SC";
		font-weight: 300;
		line-height: 33rpx;
		color: #FF5D58;
		margin-right: 32rpx;
	}

	.item .list:first-child {
		border-top: 4rpx solid #F3F4F8;
	}

	.add {
		position: fixed;
		right: 36rpx;
		bottom: 102rpx;
		width: 80rpx;
		height: 80rpx;
		border-radius: 50%;
		font-size: 60rpx;
		line-height: 77rpx;
		text-align: center;
		color: #FFFFFF;
		background-color: #2E6ADF;
	}

	/* 正在进行时的状态颜色 */
	.zhengZai {
		background-color: #e4cb0c;
	}

	/* 完成进行时的状态颜色 */
	.fishu {
		background-color: #008c8c;
	}
</style>
